package com.twb.core.base;

import com.fasterxml.jackson.annotation.JsonInclude;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @Title  Result
 * @Description 前端返回对象
 * @author DSY
 * @date 2018-10-17 13:42
 */
@ApiModel(value="Result",description="返回结果")
public class Result<T> implements Serializable {
	private static final long serialVersionUID = 1430633339880116031L;

	/**
	 * 成功与否标志
	 */
	@ApiModelProperty("成功与否标志")
	private boolean success = true;
	/**
	 * 返回状态码，默认200.前端需要拦截一些常见的状态码如403、404、500等
	 */
	@JsonInclude(JsonInclude.Include.NON_NULL)
	@ApiModelProperty("返回状态码")
	private Integer status = 200;
	/**
	 * 编码，可用于前端处理多语言，不需要则不用返回编码
	 */
	@JsonInclude(JsonInclude.Include.NON_NULL)
	@ApiModelProperty("返回编码")
	private String code;
	/**
	 * 相关消息
	 */
	@JsonInclude(JsonInclude.Include.NON_NULL)
	@ApiModelProperty("返回消息")
	private String message;
	/**
	 * 相关数据
	 */
	@JsonInclude(JsonInclude.Include.NON_NULL)
	@ApiModelProperty("返回数据")
	private T data;

	public Result() {
	}

	public Result(boolean success) {
		this.success = success;
	}

	public Result(boolean success, Integer status) {
		this.success = success;
		this.status = status;
	}

	public Result(boolean success, String code, String msg) {
		this(success);
		this.code = code;
		this.message = msg;
	}

	public Result(boolean success, Integer status, String code, String msg) {
		this.success = success;
		this.status = status;
		this.code = code;
		this.message = msg;
	}

	public Result(boolean success, String code, String msg, T data) {
		this(success);
		this.code = code;
		this.message = msg;
		this.data = data;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String msg) {
		this.message = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}